﻿namespace LearnMAUI2.Services;

//注意其接口在Lib中
//MAUI的Preferences只支持日期，数字，字符串
public class PreferenceStorage : IPreferenceStorage
{
    public int Get(string key, int defaultValue) => Preferences.Get(key, defaultValue);

    public string Get(string key, string defaultValue) => Preferences.Get(key, defaultValue);

    public void Set(string key, int value) => Preferences.Set(key, value);

    public void Set(string key, string value) => Preferences.Set(key, value);
    public void Set(string key, DateTime value) => Preferences.Set(key, value);

    public DateTime Get(string key, DateTime defaultValue)
    {
        var value = Preferences.Get(key, defaultValue);
        return value == default ? defaultValue : value;
    }
}